package com.newsmanagement.controller.admin;


import com.newsmanagement.domain.dto.NodeInfoPageDto;
import com.newsmanagement.domain.pojo.NodeInfo;
import com.newsmanagement.domain.pojo.PageBean;
import com.newsmanagement.domain.pojo.Result;
import com.newsmanagement.domain.pojo.User;
import com.newsmanagement.domain.vo.NodeProvVo;
import com.newsmanagement.domain.vo.NodeTypeNameVo;
import com.newsmanagement.domain.vo.NodeTypeVo;
import com.newsmanagement.service.NodeInfoService;
import com.newsmanagement.service.UserService;
import com.newsmanagement.utils.Md5Util;
import com.newsmanagement.utils.ThreadLocalUtil;
import jakarta.validation.constraints.Pattern;
import org.hibernate.validator.constraints.URL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 节点企业信息接口
 */
@RestController
@RequestMapping("/admin/nodeInfo")
@Validated
public class NodeInfoAdminController {

    @Autowired
    private UserService userService;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private NodeInfoService nodeInfoService;


    /**
     * 分页查询节点信息列表
     * @return
     */
    @GetMapping("/page")
    public Result<PageBean<NodeInfo>> page(NodeInfoPageDto nodeInfoPageDto){
        PageBean<NodeInfo> page = nodeInfoService.pageNodeInfo(nodeInfoPageDto);
        return Result.success(page);
    }

    /**
     * 新增企业节点
     */
    @PostMapping
    public Result<Boolean> save(@RequestBody NodeInfo nodeInfo){
        return Result.success(nodeInfoService.add(nodeInfo));
    }

    /**
     * 修改企业节点信息
     */
    @PutMapping
    public Result<Boolean> update(@RequestBody NodeInfo nodeInfo){
        return Result.success(nodeInfoService.updateNodeInfo(nodeInfo));
    }

    /**
     * 删除企业节点
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@PathVariable Integer id){
        return Result.success(nodeInfoService.removeNodeInfoById(id));
    }

    /**
     * 前端图表获取节点增长趋势
     */
    @GetMapping("/getNodeTrend")
    public Result<Map<String, Object>> getNodeTrend(){
        Map<String, Object> map = nodeInfoService.getNodeTrend();
        return Result.success(map);
    }

    @GetMapping("/getNodeProv")
    public Result<List<NodeProvVo>> getNodeProv(){
        List<NodeProvVo> list = nodeInfoService.getNodeProv();
        return Result.success(list);
    }

    @GetMapping("/getNodeType")
    public Result<List<NodeTypeNameVo>> getNodeType(){
        return Result.success(nodeInfoService.getNodeType());
    }
}
